s = str(input())
if len(s) != 4:
    print(0)
else:
    k = 0
    x1 = int(s[0])
    x2 = int(s[1])
    x3 = int(s[2])
    x4 = int(s[3])
    x123 = int(s[0:3])
    x432 = int(s[1:4])
    x1234 = int(s)
    x12 = int(s[0:2])
    x23 = int(s[1:3])
    x34 = int(s[2:4])
    a = [x1, x2, x3, x4, x123, x432, x1234, x12, x23, x34]
    b = 0
    for i in a:
        k = 0
        for z in range(2,i):
            if i % z == 0:
                k += 1
        if k == 0:
            if i > b:
                b = i
    print(b)
